package com.fzj.ivos_serve.vehicle.service.impl;

import com.fzj.ivos_serve.vehicle.mapper.VehicleMapper;
import com.fzj.ivos_serve.vehicle.pojo.dto.VehicleQuery;
import com.fzj.ivos_serve.vehicle.pojo.dto.VehicleSaveParam;
import com.fzj.ivos_serve.vehicle.pojo.entity.Vehicle;
import com.fzj.ivos_serve.vehicle.pojo.vo.VehicleVO;
import com.fzj.ivos_serve.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class VehicleServiceImpl implements VehicleService {
    @Autowired
    private VehicleMapper vehicleMapper;

    @Override
    public void saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息业务，参数：{}",vehicleSaveParam);
        Vehicle vehicle = new Vehicle();
        BeanUtils.copyProperties(vehicleSaveParam,vehicle);
        if(vehicleSaveParam.getId()==null){
            //新增业务
            vehicle.setStatus("1");//空闲1，占用2
            vehicle.setGeofenceBindStatus("0");//已绑定1，未绑定0
            vehicle.setCreateTime(new Date());
            log.debug("存入的车辆信息：{}",vehicle);
            vehicleMapper.insert(vehicle);
        }else{
            //修改业务
            vehicle.setUpdateTime(new Date());
            log.debug("存入的车辆信息：{}",vehicle);
            vehicleMapper.update(vehicle);
        }
    }

    @Override
    public List<VehicleVO> selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息业务，参数：{}",vehicleQuery);
        List<VehicleVO> vehicleVOList = vehicleMapper.select(vehicleQuery);
        log.debug("查询出的车辆信息：{}",vehicleVOList);
        return vehicleVOList;
    }

    @Override
    public void deleteVehicleById(Long id) {
        log.debug("根据车辆id删除车辆业务，参数：{}",id);
        vehicleMapper.deleteById(id);
    }
}
